﻿using Microsoft.VisualStudio.TestTools.UITesting;

namespace CodedUITestExtensions
{
    /// <summary>
    /// Class for run application.
    /// </summary>
    public static class AppRunner
    {
        /// <summary>
        /// Runs application.
        /// </summary>
        /// <param name="appPath">Application exe file path.</param>
        /// <param name="closeOnPlaybackCleanup">The option of closing the application after each test.</param>
        /// <returns>Running application.</returns>
        public static ApplicationUnderTest RunApplication(string appPath, bool closeOnPlaybackCleanup = false)
        {
            var app = ApplicationUnderTest.Launch(appPath);
            app.CloseOnPlaybackCleanup = closeOnPlaybackCleanup;
            return app;

        }

        /// <summary>
        /// Closes application.
        /// </summary>
        /// <param name="application">Application.</param>
        public static void CloseApplication(ApplicationUnderTest application)
        {
            application.Close();
        }
    }
}
